home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
a_utils
/
expanded.lha
/
test_suite
/
testgeob.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-19
|
16KB
|
722 lines
//
// Linear-Affine-Projective Geometry Package
//
// testgeob.C
//
// $Header$
//
// William J.R. Longabaugh
// University of Washington
//
// Test programs for the linear-affine-projective geometry
// package described in William J.R. Longabaugh, "An Expanded
// System for Coordinate-Free Geometric Programming", Master's
// thesis, University of Washington, 1992.
//
// Copyright (c) 1992, William J.R. Longabaugh
// Copying, use and development for non-commercial purposes permitted.
// All rights for commercial use reserved.
// This software is unsupported and without warranty; it is
// provided "as is".
//
// ***********************************************************************
#include "Lap.h"
#include <math.h>
extern void test1(void);
extern void test2(void);
extern void test3(void);
extern void test4(void);
extern void test5(void);
extern void test6(void);
extern void test7(void);
// ***********************************************************************
int main(void)
{
test1();
test2();
test3();
test4();
test5();
test6();
test7();
return (0);
}
// ***********************************************************************
// Test the casting of maps and multimaps to geobs:
void test1(void)
{
cout << "ENTERING TEST1\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", v, a);
// Create a first order map and convert it to a Multimap:
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
APoint a2(fra, ScalarList(2.2, 5.1, 1.0));
APoint a3(fra, ScalarList(-6.7, 2.3, 1.0));
Simplex s1("test simplex", a, GeObList(a1, a2, a3));
AffineMap am(a.StdSimplex(), s1);
cout << am;
MAM multi(am);
cout << multi;
MAM noargp;
noargp = multi(GeObList(fra[2]));
APoint tst(noargp);
cout << tst;
MAM noargv;
noargv = multi(GeObList(fra[0]));
AVector tstv(noargv);
cout << tstv;
// Create a MLM linear functional and convert it to a dual vector
Vector v1(v.StdBasis(), ScalarList(4.5, 6.2, 3.6));
Vector vd = v1.Dual();
MLM multilf(vd);
Vector vdn(multilf);
cout << vdn;
// Convert a Linear Map functional into a dual vector:
LinearMap lm(vd);
Vector vdn2(lm);
cout << vdn2;
}
// ***********************************************************************
// Tests of auto scalars
void test2(void)
{
cout << "ENTERING TEST2\n";
GeOb myreal(4.6);
cout << myreal;
Scalar foo = myreal.ToScalar();
cout << foo << "\n";
}
// ***********************************************************************
// Tests of tuple creation, referencing, and setting
void test3(void)
{
cout << "ENTERING TEST3\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", TRUE, v);
VSpace t = a.GetSpace(TANGENT);
VSpace cv1("Cartesian vspace1", SpaceList(v, v, v), FALSE);
VSpace cv2("Cartesian vspace1", SpaceList(v, t), FALSE);
ASpace ca1("Cartesian aspace1", SpaceList(a, a, a), FALSE);
VSpace ct1 = ca1.GetSpace(TANGENT);
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
APoint a3(fra, ScalarList(-1.1, 6.3, 1.0));
AVector av1 = a2 - a3;
Basis bas = v.StdBasis();
Vector v1(bas, ScalarList(2.1, 5.4, 8.9));
Vector v2(bas, ScalarList(7.8, 3.5, 1.1));
Vector v3(bas, ScalarList(-1.1, 6.3, -2.8));
// Create tuples:
Vector vt(cv1, GeObList(av1, v2, a3));
Vector vt2(cv2, GeObList(v2, av1));
APoint pt(ca1, GeObList(a1 + av1, (a2 + a3) / 2.0, a3));
APoint pt2(ca1, GeObList(a1, a2, a3));
AVector avt(ct1, GeObList(av1, a1 - a2, a3 -a1));
// Reference elements:
PPoint vtpp = VectorEC(vt);
GeOb tst1 = avt[0];
cout << tst1;
tst1 = avt[2];
cout << tst1;
GeOb tst2 = vt2[1];
cout << tst2;
tst2 = vtpp[0]; // Note autocasting
cout << tst2;
tst2 = vt[2];
cout << tst2;
GeOb tst3 = pt[0];
cout << tst3;
tst3 = pt[2];
cout << tst3;
GeObList tst4 = vtpp.TupleElements();
cout << tst4;
// Modify elements:
tst1 = avt.SetTupleElement(0, a2 - a1);
cout << tst1;
tst1 = avt.SetTupleElement(2, av1);
cout << tst1;
tst2 = vt2.SetTupleElement(1, a1 - a1);
cout << tst2;
tst2 = vtpp.SetTupleElement(0, v2); // Note autocasting
cout << tst2;
tst2 = vt.SetTupleElement(2, a2);
cout << tst2;
tst3 = pt.SetTupleElement(0, a3);
cout << tst3;
tst3 = pt.SetTupleElement(2, a3 + av1);
cout << tst3;
}
// ***********************************************************************
// Algebraic operations:
void test4(void)
{
cout << "ENTERING TEST4\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", v, a);
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
APoint a3(fra, ScalarList(-3.4, 2.8, 1.0));
AVector av1 = a2 - a3;
AVector av2 = a3 - a1;
AVectorEC avec1(av1);
AVectorEC avec2(av2);
Basis bas = v.StdBasis();
Vector v1(bas, ScalarList(2.1, 5.4, 8.9));
Vector v2(bas, ScalarList(7.8, 3.5, 1.1));
VectorEC vec1(v1);
VectorEC vec2(v2);
PPoint pp1(a1);
// Add, subtract two vectors, 2 affine vectors, affine/avec combinations,
// general combinations:
GeOb ret = v1 + v2;
cout << ret;
ret = v1 - v2;
cout << ret;
ret = av1 + av2;
cout << ret;
ret = av1 - av2;
cout << ret;
ret = avec1 + avec2;
cout << ret;
ret = avec1 - avec2;
cout << ret;
ret = avec1 + av2;
cout << ret;
ret = av1 - avec2;
cout << ret;
ret = pp1 + a2;
cout << ret;
ret = a2 - pp1;
cout << ret;
ret = vec1 + a2;
cout << ret;
ret = a1 - av1;
cout << ret;
// Multiplication and division:
Vector val(4.0);
ret = val * av1;
cout << ret;
ret = avec1 * val;
cout << ret;
ret = a1 * val;
cout << ret;
ret = av1 / val;
cout << ret;
ret = avec1 / val;
cout << ret;
ret = a1 / val;
cout << ret;
}
// ***********************************************************************
// Duals and application:
void test5(void)
{
cout << "ENTERING TEST5\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", v, a);
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
APoint a2(fra, ScalarList(2.5, 7.8, 1.0));
APoint a3(fra, ScalarList(-3.4, 2.8, 1.0));
AVector av1 = a2 - a3;
AVector av2 = a3 - a1;
AVectorEC avec1(av1);
AVectorEC avec2(av2);
Basis bas = v.StdBasis();
Vector v1(bas, ScalarList(2.1, 5.4, 8.9));
Vector v2(bas, ScalarList(7.8, 3.5, 1.1));
Vector v3 = av1;
VectorEC vec1(v1);
VectorEC vec2(v2);
PPoint pp1(a1);
GeOb ret1 = v1.Dual();
cout << ret1;
GeOb ret2 = av1.Dual();
cout << ret2;
GeOb ret3 = avec1.Dual();
cout << ret3;
GeOb ret4 = a2.Dual();
cout << ret4;
GeOb ret5 = pp1.Dual();
cout << ret5;
VectorEC vec3(ret2);
Scalar val;
val = ret1.Apply(v2);
cout << val << "\n";
val = av2.Apply(ret2);
cout << val << "\n";
val = ret2.Apply(v3);
cout << val << "\n";
val = ret1.Apply(a1);
cout << val << "\n";
val = avec1.Apply(ret2);
cout << val << "\n";
val = pp1.Apply(ret1);
cout << val << "\n";
val = vec3.Apply(av1);
cout << val << "\n";
val = av2.Apply(vec3);
cout << val << "\n";
}
// ***********************************************************************
// Various mappings:
void test6(void)
{
cout << "ENTERING TEST6\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", v, a);
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(3.6, -4.5, 1.0));
AVector av1(fra, ScalarList(4.5, 2.1, 0.0));
AVectorEC avec1(av1);
Vector v1(a1);
Vector v2(av1);
VectorEC vec1(v1);
VectorEC vec2(v2);
PPoint pp1(a1);
HFrame hfra = p.StdBasis();
PPoint pp2(avec1);
GeOb ret;
// APOINT
if (a1.CanMapTo(AFF_POINT)) {
ret = a1.MapTo(AFF_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (a1.CanMapTo(AFF_VECTOR)) {
ret = a1.MapTo(AFF_VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (a1.CanMapTo(AFF_VEC_EC)) {
ret = a1.MapTo(AFF_VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (a1.CanMapTo(VECTOR)) {
ret = a1.MapTo(VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (a1.CanMapTo(VEC_EC)) {
ret = a1.MapTo(VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (a1.CanMapTo(PROJ_POINT)) {
ret = a1.MapTo(PROJ_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
// AVECTOR
if (av1.CanMapTo(AFF_POINT)) {
ret = av1.MapTo(AFF_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (av1.CanMapTo(AFF_VECTOR)) {
ret = av1.MapTo(AFF_VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (av1.CanMapTo(AFF_VEC_EC)) {
ret = av1.MapTo(AFF_VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (av1.CanMapTo(VECTOR)) {
ret = av1.MapTo(VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (av1.CanMapTo(VEC_EC)) {
ret = av1.MapTo(VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (av1.CanMapTo(PROJ_POINT)) {
ret = av1.MapTo(PROJ_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
// AVECTOREC
if (avec1.CanMapTo(AFF_POINT)) {
ret = avec1.MapTo(AFF_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (avec1.CanMapTo(AFF_VECTOR)) {
ret = avec1.MapTo(AFF_VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (avec1.CanMapTo(AFF_VEC_EC)) {
ret = avec1.MapTo(AFF_VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (avec1.CanMapTo(VECTOR)) {
ret = avec1.MapTo(VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (avec1.CanMapTo(VEC_EC)) {
ret = avec1.MapTo(VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (avec1.CanMapTo(PROJ_POINT)) {
ret = avec1.MapTo(PROJ_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
// VECTOR
if (v1.CanMapTo(AFF_POINT)) {
ret = v1.MapTo(AFF_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (v2.CanMapTo(AFF_POINT)) {
ret = v2.MapTo(AFF_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (v1.CanMapTo(AFF_VECTOR)) {
ret = v1.MapTo(AFF_VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (v2.CanMapTo(AFF_VECTOR)) {
ret = v2.MapTo(AFF_VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (v1.CanMapTo(AFF_VEC_EC)) {
ret = v1.MapTo(AFF_VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (v2.CanMapTo(AFF_VEC_EC)) {
ret = v2.MapTo(AFF_VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (v1.CanMapTo(VECTOR)) {
ret = v1.MapTo(VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (v1.CanMapTo(VEC_EC)) {
ret = v1.MapTo(VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (v1.CanMapTo(PROJ_POINT)) {
ret = v1.MapTo(PROJ_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (v2.CanMapTo(PROJ_POINT)) {
ret = v2.MapTo(PROJ_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
// VECTOREC
if (vec1.CanMapTo(AFF_POINT)) {
ret = vec1.MapTo(AFF_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (vec2.CanMapTo(AFF_POINT)) {
ret = vec2.MapTo(AFF_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (vec1.CanMapTo(AFF_VECTOR)) {
ret = vec1.MapTo(AFF_VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (vec2.CanMapTo(AFF_VECTOR)) {
ret = vec2.MapTo(AFF_VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (vec1.CanMapTo(AFF_VEC_EC)) {
ret = vec1.MapTo(AFF_VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (vec2.CanMapTo(AFF_VEC_EC)) {
ret = vec2.MapTo(AFF_VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (vec1.CanMapTo(VECTOR)) {
ret = vec1.MapTo(VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (vec1.CanMapTo(VEC_EC)) {
ret = vec1.MapTo(VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (vec1.CanMapTo(PROJ_POINT)) {
ret = vec1.MapTo(PROJ_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (vec2.CanMapTo(PROJ_POINT)) {
ret = vec2.MapTo(PROJ_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
// PROJECTIVE_POINT
if (pp1.CanMapTo(AFF_POINT)) {
ret = pp1.MapTo(AFF_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (pp2.CanMapTo(AFF_POINT)) {
ret = pp2.MapTo(AFF_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (pp1.CanMapTo(AFF_VECTOR)) {
ret = pp1.MapTo(AFF_VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (pp2.CanMapTo(AFF_VECTOR)) {
ret = pp2.MapTo(AFF_VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (pp1.CanMapTo(AFF_VEC_EC)) {
ret = pp1.MapTo(AFF_VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (pp2.CanMapTo(AFF_VEC_EC)) {
ret = pp2.MapTo(AFF_VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (pp1.CanMapTo(VECTOR)) {
ret = pp1.MapTo(VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (pp2.CanMapTo(VECTOR)) {
ret = pp2.MapTo(VECTOR);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (pp1.CanMapTo(VEC_EC)) {
ret = pp1.MapTo(VEC_EC);
cout << ret;
} else {
cout << "Cannot Map\n";
}
if (pp1.CanMapTo(PROJ_POINT)) {
ret = pp1.MapTo(PROJ_POINT);
cout << ret;
} else {
cout << "Cannot Map\n";
}
}
// ***********************************************************************
// Cross ratio calculations:
void test7(void)
{
cout << "ENTERING TEST7\n";
VSpace v("Test vector space", 3, TRUE);
ASpace a("Test affine space", 2, TRUE);
PSpace p("Test projective space", v, a);
// Build four collinear points, map to various objects:
Frame fra = a.StdBasis();
APoint a1(fra, ScalarList(0.0, 2.0, 1.0));
APoint a2(fra, ScalarList(0.0, 3.0, 1.0));
APoint a3 = (.5 * a1) + (.5 * a2);
APoint a4 = (.75 * a1) + (.25 * a2);
Vector v1 = a1;
Vector v2 = a2;
Vector v3 = a3;
Vector v4 = a4;
PPoint p1 = a1;
PPoint p2 = a2;
PPoint p3 = a3;
PPoint p4 = a4;
GeOb ret;
AugScalar augi(INFINITY);
AugScalar aug0(0.0);
AugScalar aug1(1.0);
AugScalar aug2(2.0);
GeObList lst1(a1, v2, p3);
ret = CrossRatio(augi, lst1);
cout << ret;
ret = CrossRatio(aug0, lst1);
cout << ret;
ret = CrossRatio(aug1, lst1);
cout << ret;
ret = CrossRatio(aug2, lst1);
cout << ret;
GeObList lst2(a1, v2, p3, ret);
AugScalar val = CrossRatioCalc(lst2);
cout << val;
lst2 = GeObList(a1, a2, a3, a1);
val = CrossRatioCalc(lst2);
cout << val;
lst2 = GeObList(a1, a2, a3, a2);
val = CrossRatioCalc(lst2);
cout << val;
lst2 = GeObList(a1, a2, a3, a3);
val = CrossRatioCalc(lst2);
cout << val;
lst2 = GeObList(a3, a3, a2, a1);
val = CrossRatioCalc(lst2);
cout << val;
}
// ***********************************************************************